﻿using System;
using System.Threading;
using System.Web;
using System.Web.UI;
using UDS.Components;

namespace UDS.WebApp.SubModule
{
    public class CFPageBase : PageBase
    {
        private int _canManageCF;

        /// <summary>
        /// Determines whether the current user has the "ManageCommonFile" permission.
        /// </summary>
        protected bool CanManageCF
        {
            get
            {
                const int NotSet = 0;
                const int CAN = 1;
                const int CANNOT = 2;

                if (_canManageCF == NotSet)
                {
                    SiteContext context = SiteContext.Current;
                    Interlocked.CompareExchange(
                        ref _canManageCF,
                        AssignRights.IsAccessAllowed(context.UserName, context.ActiveNodeID, PermissionType.ManageCommonFile) ? CAN : CANNOT,
                        NotSet);
                }
                return _canManageCF == CAN;
            }
        }
    }
}
